<template>
	<view>
		<u-loading-page :loading="loadding" loading-mode="semicircle" loading-text="加载中"></u-loading-page>
		<view v-if="!loadding">
			<u-sticky>
				<view class="search">
					<u-search placeholder="关键字" v-model="keyword" :showAction="false" bgColor="#ffffff" @search="searchs"></u-search>
				</view>
			</u-sticky>
			<view class="team_box" v-if="data !== undefined && data!== null && data.length>0">
				<view v-for="(item,index) in data" :key="index" class="lists">
					<view class="team_list" @click="info(item.id)">
						<view class="team_top">
							<view class="team_top_title">
								<u-icon :label="item.name" size="15" space="8px" color="#1296db"
									name="account-fill"></u-icon>
							</view>
							<view class="team_top_title" style="padding-top: 18rpx;">
								<u-icon :label="item.phone" size="15" space="8px" color="#1296db"
									name="phone-fill"></u-icon>
							</view>
							<view class="team_top_title" style="padding-top: 18rpx;">
								<u-icon :label="item.create_time" size="15" labelSize="12" labelColor="#c8c9cc" space="8px"
									color="#1296db" name="clock-fill"></u-icon>
							</view>
						</view>
						<view class="team_bottom">
							<view v-if="item.policyNum < 6" class="msg">
								政策未配置完成
							</view>
							<view class="policy">
								<text>政策</text>
								<u-icon name="arrow-right"></u-icon>
							</view>
						</view>
					</view>
					<!-- <view class="stateSwitch">
						<view v-if="userinfo.hzy_state == 1" class="state-item">
							<text>星展业开关：</text>
							<u-switch
								v-model="item.hzy_state"
								asyncChange
								:activeValue="1"
								:inactiveValue="2"
								@change="hzyStateChange(item)"
							></u-switch>
						</view>
					</view> -->
				</view>
			</view>
			<u-empty class="policy_box" v-else mode="list" icon="/static/Empty/data_null.png">
			</u-empty>
		</view>
	</view>
</template>

<script>
import { data } from '../../../uni_modules/uview-ui/libs/mixin/mixin';

	export default {
		data() {
			return {
				loadding: true,
				display: false,
				data: [],
				keyword: '',
				userinfo: {}
			}
		},
		onLoad() {
			this.userinfo = uni.getStorageSync('userinfo')
			this.getUserInfo()
		},
		onShow() {
			this._request()
		},
		methods: {
			// 搜索
			searchs() {
				this._request()
			},
			// 加载代理数据
			async _request() {
				const {
					data: res
				} = await this.$myHttp({
					url: 'Team/getMyTeamList',
					data: {
						keyword: this.keyword
					}
				});
				this.loadding = false
				if (res.code == 200) {
					this.data = res.data
					this.display = true
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'none',
						duration: 3000
					})
				}
			},
			// 政策
			info(id) {
				uni.navigateTo({
					url: '/pages/hzy/team/policyNew?id=' + id
				})
			},
			// 星展业权限
			hzyStateChange(datas) {
				uni.showModal({
					content: datas.hzy_state == 2 ? '确定要开启吗' : '确定要关闭吗',
					success: (res) => {
						if (res.confirm) {
							if (datas.hzy_state == 2) {
								datas.hzy_state = 1
							} else {
								datas.hzy_state = 2
							}
							this.setAgentHzyAuth(datas, 4)
						}
					}
				})
			},
			// 星展业权限
			async setAgentHzyAuth(data, type) {
				var _this = this
				uni.showLoading({
					title: '加载中'
				});
				const {
					data: res
				} = await this.$myHttp({
					url: 'v1/setAgentRateAuth',
					data: {
						type: type,
						agent_id: data.id,
						hzy_state: data.hzy_state,
					}
				});
				uni.hideLoading()
				uni.showToast({
					title: res.msg,
					icon: 'none',
					duration: 2000
				})
			},
			// 获取用户信息
			async getUserInfo() {
				const {
					data: res
				} = await this.$myHttp({
					url: 'user/getUserInfo'
				});
				if (res.code == 200) {
					uni.setStorageSync('userinfo', res.data);
					this.userinfo = res.data
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #F2F6FC;
	}
	.search {
		padding: 20rpx;
		background-color: #F2F6FC;
	}
	.team_box {
		padding: 0 20rpx 20rpx 20rpx;
		box-sizing: border-box;
		color: #909399;

		.team_top_title {
			display: flex;
			margin: 6rpx 0;
			align-items: center;
			
			.platform_tags {
				margin-left: 10rpx;
				padding: 2rpx 8rpx;
				border-radius: 10rpx;
				color: #ffffff;
				font-size: 24rpx;
				margin-top: 20rpx;
			}
			
			.blues {
				background-color: #2979ff;
			}
			
			.reds {
				background-color: #fa3534;
			}
		}
		
		.lists {
			box-sizing: border-box;
			padding: 20rpx;
			box-shadow: 7px 0px 30px -18px #888888;
			background-color: #ffffff;
			margin-bottom: 20rpx;
			
			.team_list {
				display: flex;
				align-items: center;
				justify-content: space-between;
				position: relative;
			
				.team_top {
					display: flex;
					flex-direction: column;
			
					text {
						margin-bottom: 20rpx;
					}
				}
			
				.team_bottom {
					
					.msg {
						font-size: 24rpx;
						position: absolute;
						top: 4rpx;
						right: 10rpx;
						display: flex;
						color: #fa3534;
					}
					
					.policy {
						display: flex;
									
						text {
							font-size: 30rpx;
							margin-right: 6rpx;
							color: #82848a;
						}
					}
				}
			}
		
			.stateSwitch {
				
				.state-item {
					font-size: 30rpx;
					padding: 20rpx 0;
					display: flex;
					justify-content: space-between;
					align-items: center;
					border-bottom: 1px dashed #F2F6FC;
				}
			}
		}
	}
</style>